<?php
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;

class User extends  Base
{

    //友情链接列表
    public function index()
    {
      $userData=Db::name('users')->paginate(15);
      return view('',[
         'userData'=>$userData,
         'left_menu'=>3
        ]);

    }
   
    public function edit()
    {
      $id=input('get.id');  
      $userData=Db::name('users')->where('id',$id)->find();
       if(request()->isPost()){
         $dataress = input('post.'); 
         $data['username'] =$dataress['username'];
         $data['busername'] =$dataress['busername'];
         $data['amount'] = $userData['amount']+$dataress['amount'];
         $data['email'] =$dataress['email'];
         if($data['password']=$userData['password']){
           $data['password']=$userData['password'];
         }else{
           $data['password']=$this->password_salt($dataress['password']);  
         }
         if($dataress['time'] !== NULL){
           if($userData['overtime'] !== NULL){
           $data['vip'] ='1';
           $data['viptime'] =$userData['viptime'];
           $data['overtime'] =$userData['overtime']+$dataress['time']*24*60*60;
         }else{
           $data['vip'] ='1';
           $data['viptime'] =time();
           $data['overtime'] =time+$dataress['time']*24*60*60;
         }  
         }
        else{
             $data['vip'] ='0'; 
         }
        
            $res=Db::name('users')->where('id',$id)->update($data);

            if($res){
				return alert('添加数据成功！跳转至参数设置','index',6,3);
			 }else{
				return alert('操作失败！','index',5,3);
			 }
       }
      return view('',[
         'userData'=>$userData,
         'left_menu'=>3
        ]);

    }
     public function add()
    {
       if(request()->isPost()){
         $dataress = input('post.'); 
         $data['username'] =$dataress['username'];
         $data['busername'] =$dataress['busername'];
         $data['amount'] =$dataress['amount'];
         $data['email'] =$dataress['email'];
         $data['status'] ='3';
         $data['password']=$this->password_salt($dataress['password']);
         if($dataress['time'] !== NULL ){
           $data['vip'] ='1';
           $data['viptime'] =time();
           $data['overtime'] =time()+$dataress['time']*24*60*60;
         }else{
             $data['vip'] ='0'; 
         }
        
         $res=Db::name('users')->insert($data);
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
       }
      
      return view('',[
      
        ]);

    }
    public function del()
    {
       $id=input('id');//助手函数

      $res=Db::name('users')->delete($id);
      if($res){
            return alert('删除成功!','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         } 
    }
      public function order()
   {
      $userData=Db::name('order')->where('a.status',2)
       ->alias('a')->join('daili b','a.dailiuid=b.id')->field('a.*,b.beizhu')->select()->toArray();
     
      return view('',[
         'orderData'=>$userData,
      
        ]);

    }
    /*添加*/
   
    
    
}
